﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.Media.Animation;

namespace App16._4
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
    }

    public class NewPointAnimation : AnimationTimeline
    {
        public NewPointAnimation()
            : base()
        { }

        public override object GetCurrentValue(object defaultOriginValue, 
            object defaultDestinationValue, AnimationClock animationClock)
        {
            if (!animationClock.CurrentProgress.HasValue)
                return null;

            Double progress = animationClock.CurrentProgress.Value;

            Point curPoint = new Point();
            curPoint.X = From.X * (1 - progress) + To.X * progress;
            curPoint.Y = From.Y * (1 - progress) + To.Y * progress;

            return curPoint;
        }

        protected override Freezable CreateInstanceCore()
        {
            return new NewPointAnimation();
        }

        public override bool IsDestinationDefault
        {
            get { return base.IsDestinationDefault; }
        }

        public override Type TargetPropertyType
        {
            get { return typeof(Point); }
        }

        public Point From
        {
            get { return (Point)GetValue(FromProperty); }
            set { SetValue(FromProperty, value); }
        }

        public Point To
        {
            get { return (Point)GetValue(ToProperty); }
            set { SetValue(ToProperty, value); }
        }

        public static readonly DependencyProperty FromProperty =
            DependencyProperty.Register("From", typeof(Point), typeof(NewPointAnimation));
        public static readonly DependencyProperty ToProperty =
            DependencyProperty.Register("To", typeof(Point), typeof(NewPointAnimation));
    }
}
